package cn.edu.fzu.homemaking.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.*;

import cn.edu.fzu.homemaking.api.SsoApi;
import cn.edu.fzu.homemaking.domain.enums.SexEnum;
import cn.edu.fzu.homemaking.domain.enums.StatusEnum;
import cn.edu.fzu.homemaking.service.SysCusUserService;
import cn.edu.fzu.homemaking.web.Result;
import io.swagger.annotations.*;

/**
 * @author yifan
 * @date 2023/4/6
 */
@Api(tags = "sys-顾客管理")
@RestController
@RequestMapping("/api/sys")
public class SysCusUserController {

    @Resource
    SsoApi ssoApi;

    @Resource
    private SysCusUserService sysCusUserService;

    @ApiOperation(value = "获取顾客列表", httpMethod = "GET")
    @ApiResponse(code = 200, message = "", response = Result.class)
    @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", required = true, value = "页码"),
            @ApiImplicitParam(name = "pageSize", required = true, value = "页面大小"),
            @ApiImplicitParam(name = "email", required = false, value = "邮箱"),
            @ApiImplicitParam(name = "name", required = false, value = "名字"),
            @ApiImplicitParam(name = "sex", required = false, value = "-1-保密，0-男，1-女"),
            @ApiImplicitParam(name = "status", required = false, value = "-1-删除，0-正常，1-禁用") })
    @GetMapping("auth/cususer/list")
    @ResponseBody
    public Result list(String name, String email, SexEnum sex, String phone, StatusEnum status, Integer pageNum,
                       Integer pageSize, HttpServletRequest request) {
        Result result = ssoApi.listCustomerUser(email, name, sex, phone, status, pageNum, pageSize);
        return result;
    }


    @PostMapping("auth/cususer/update")
    @ApiOperation(value = "更新顾客信息接口")
    @ApiImplicitParams({ @ApiImplicitParam(name = "email", required = true, value = "邮箱"),
            @ApiImplicitParam(name = "phone", required = false, value = "手机号"),
            @ApiImplicitParam(name = "address", required = false, value = "家庭地址"),
            @ApiImplicitParam(name = "faceUrl", required = false, value = "人脸照片"),
            @ApiImplicitParam(name = "status", required = false, value = "-1-删除，0-正常，1-禁用") })
    @ResponseBody
    public Result update(String name, String email, String phone, String address, String faceUrl,
                         StatusEnum status, HttpServletRequest request) {
        Result result = sysCusUserService.update(name, email, phone, address, faceUrl, status);
        return result;
    }
}
